from typing import *


class Solution:
    def minimumArea(self, grid: List[List[int]]) -> int:
        m, n = len(grid), len(grid[0])
        l, r, u, d = n, 0, m, 0
        for i in range(m):
            for j in range(n):
                if grid[i][j] == 1:
                    l = min(l, j)
                    r = max(r, j)
                    u = min(u, i)
                    d = max(d, i)
        return (r - l + 1) * (d - u + 1)
